package org.example.service.logger;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.omg.CORBA.Object;

import java.util.Arrays;

public class AroundLogger {
    private static final Logger log = Logger.getLogger(AfterLogger.class);
    public Object aroundLogger(ProceedingJoinPoint jp)throws Throwable{
        log.info("调用"+jp.getTarget()+"的"+jp.getSignature().getName()+
                "方法。方法入参："+ Arrays.toString(jp.getArgs()));
        Object result=null;
        try{
            result = (Object) jp.proceed(); //执行目标方法斌获得返回值
            log.info("调用"+jp.getTarget()+"的"+jp.getSignature().getName()+
                    "方法。返回值："+result);

        }catch (Throwable e){
            log.error(jp.getSignature().getName()+"方法发生异常:"+e);
        }finally {
            log.error(jp.getSignature().getName() + "方法结束执行");
        }
        return result;
    }
}
